<?php
/**
 * Created by coder meng.
 * User: coder meng
 * Date: 2018/4/9 13:46
 */
namespace app\blog\controller;
use cmf\controller\HomeBaseController;
use app\blog\model\MenuModel as ME;
use think\Db;
class OrderController extends HomeBaseController
{
    /*
     *菜单选择
     * */
    public function index()
    {

        return $this->fetch();
    }
    /*
     * 单品
     * 提交订单
     * 规格没有整理
     * */
    public function paytype()
    {
        session_start();
        $menu=new ME();
        $shopid=50;
        if(!empty($_SESSION['think']['goods']))
        {
            $session=$_SESSION['think']['goods'];
            foreach($session as $k=>$v)
            {
                $data=array();
                if($v['setmeal']==0)
                {
                    $data['orderid']='BFT'.$shopid.$v['time'];
                    $data['goodsid']=$v['g_id'];
                    $data['format']=$v['format'];
                    $data['price']=$v['g_price'];
                    $data['money']=$v['c_money'];
                    $data['rmb']=$v['c_rmb'];
                    $data['rebateid']=$v['c_rebateid'];
                    $data['vipprice']=0;
                    $data['storeid']=$v['shop_id'];
                    $data['ctime']=$v['time'];
                    $data['stemeal']=0;
                    $data['paystatus']=0;
                    DB::name('order_detail')->insert($data);
                }else{
                    $data['orderid']='BFT'.$shopid.$v['time'];
                    $data['goodsid']=$v['set_id'];
                    $data['format']=0;
                    $data['price']=$v['g_price'];
                    $data['money']=$v['g_price'];
                    $data['rmb']=0;
                    $data['rebateid']=0;
                    $data['vipprice']=0;
                    $data['storeid']=$v['shop_id'];
                    $data['stemeal']=1;
                    $data['ctime']=$v['time'];
                    $data['paystatus']=0;
                    DB::name('order_detail')->insert($data);
                }
                $order['order']='BFT'.$shopid.$v['time'];
                session('order',$order);
            }
            $pay=$menu->setpay($session);
            $order['all_money']=$pay['s_pay'];
            session('order',$order);
            $session=$_SESSION['think']['order'];
            /*
             * 查询每个店铺的信息
             * */
             $pay=DB::name('paytype')->alias('p')->join('pay_name pm','p.pay_name = pm.id')->where(['shop_id'=>$shopid])->select();
            $this->assign('order',$session);
            $this->assign('pay',$pay);
            return $this->fetch('pay/paytype');
        }else{
            $this->success('请先选择商品！',url('menu/menu'),'',0);
        }
    }
    public function pay()
    {
           session_start();
           $session=$_SESSION['think']['orderid'];

           var_dump($session);die();
    }
}